import pycurl
import tornado
import hashlib
import threading
import datetime
import random

class ThreadClass(threading.Thread):
    def run(self):
        now = datetime.datetime.now()

        m = pycurl.CurlMulti()
        partnerId = random.randrange(50000, 50005)
	count = 2
	for i in range(count):
	    random.seed()
	    hash = random.getrandbits(128)
            c = pycurl.Curl()
	    c.setopt(pycurl.URL, "http://localhost/%s/%016x" % (partnerId, hash))
	    print "[%s] %s - (%s) %016x" % (self.getName(), now, partnerId, hash)
            m.add_handle(c)

        num_handles = count
        while num_handles:
            while 1:
                ret, num_handles = m.perform()
                if ret != pycurl.E_CALL_MULTI_PERFORM:
                    break

            m.select(1.0)	


for i in range(1):
    t = ThreadClass()
    t.start()
